<template>
	<view>
		<view @click="signClick()" class="" style="margin-top: 200rpx;">
			<view class="bottomButton flex-column-center">
				¥{{deposit}} 签约免押
			</view>
		</view>
		<view @click="quxClick()" class="" style="margin-top: 200rpx;">
			<view class="bottomButton flex-column-center">
				取消免押
			</view>
		</view>
		<!-- <view @click="chuangjian()" class="" style="margin-top: 200rpx;">
			<view class="bottomButton flex-column-center">
				创建二维码
			</view>
		</view> -->
	</view>
</template>

<script>
	const goodsDetailPlugin = requirePlugin('goodsDetailPlugin');
	import {
		toLogin,
		wxMnpLogin
	} from '@/utils/login'
	import {
		mapGetters,
		mapActions
	} from 'vuex'
import {
		test_sign,
		test_sign_query,
		test_cancel,
		createQrCode
	} from '@/api/lease.js'

	export default {
		data() {
			return {
				out_order_id:'',
				order_id:'',
				code: '',
				deposit: ''
			};
		},

		components: {

		},

		props: {},
		computed: {
			...mapGetters(["cartNum", "userInfo", "inviteCode", "appConfig"]),
		
		},
		onShow() {
			this.code = uni.getStorageSync('code')
			this.deposit = uni.getStorageSync('deposit')
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {



		},


		computed: {


		},


			
		methods: {
			chuangjian(){
				var that=this
				createQrCode({
					code:new Date().getTime(),
					deposit:0.66,
				}).then(res => {
				
				})
			},
			quxClick(){
				var that=this
				test_cancel({
					code:that.out_order_id,
					order_id:this.order_id,
				}).then(res => {
						this.showToast(res.msg)	
				})
			},
			async triggerSignLaunchMethod(params){
				 console.log(params)
				  const {success , resultCode} = await goodsDetailPlugin.triggerSignLaunchMethod(params) || {};;
				  console.log(resultCode)
				  // resultCode==6001
				  if(resultCode==9000){
					  	this.showToast('签约成功')	
				  }
				  
			},
			//弹出框
			showToast(title) {
				uni.showToast({
					title: title,
					icon: 'none',
					mask:true,
					duration:1500,
					
				});
			},
			test_sign(sourceId){
				var that=this
				test_sign({
					code:this.code,
					deposit:this.deposit,
					sourceid:sourceId
				}).then(res => {
					that.order_id=res.data.order_id
					that.out_order_id=res.data.out_order_id
					that.test_sign_query()
				})
			},
			test_sign_query(){
				var that=this
				test_sign_query({
					code:this.order_id,
					deposit:this.deposit,
				}).then(res => {
					const params = {
					      signStr: res.data.sign_str, // 授权签名字符串
					      signLaunchMethod: res.data.sign_launch_method, // 签约方式
					    }
						that.triggerSignLaunchMethod(params)
				})
			},
			signClick(){
				if (!this.isLogin){
					this.$toast({
						title: '请先登录'
					})
					setTimeout(()=>{
					toLogin();
					},1500)
					
					return
				} 
				this.code = uni.getStorageSync('code')
				this.deposit = uni.getStorageSync('deposit')
				var that=this
				
				my.checkBeforeAddOrder({
					success(res) {
						console.log(res)
				
						that.test_sign(res.sourceId)
					},
					fail({
						error,
						errorMessage
					}) {
						console.log(error, errorMessage)
					},
					complete() {
				
					},
				})
			}

		},
			
		
	};
</script>
<style lang="scss">


</style>